function filePathToBase64(filePath) {
    return new Promise((resolve, reject) => {
        wx.getFileSystemManager().readFile({
            filePath: filePath,
            encoding: 'base64',
            success: res => {
                resolve(res.data)
            },
            fail: err => {
                reject(err)
            }
        })
    })
}
//图片url转base64
function urlToBase64(url) {
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            responseType: 'arraybuffer',
            success: res => {
                let base64 = wx.arrayBufferToBase64(res.data);
                resolve(base64)
            },
            fail: err => {
                reject(err)
            }
        })
    })
}
function previewImage(urls) {
    uni.previewImage({
        urls: urls,
        longPressActions: {
            itemList: ['发送给朋友', '保存图片', '收藏'],
            success: function (data) {
            },
            fail: function (err) {
            }
        }
    });
}
function subscribeMessage() {
    uni.requestSubscribeMessage({
        tmplIds: ['v3Y3KeV6NX1_6ZPitPV6O3wjhqdGuErOHNku_ACZQkE'],
        success(res) {
        },
        fail(err) {
        }
    })
}
// 获取多边形中心点
function getPointsCenter(path) {
    let lngLen = 0, latLen = 0, lngTotal = 0, latTotal = 0, lng = 0, lat = 0;
    for (let i = 0; i < path.length; i++) {
        if (path[i].lng != null) {
            lngLen++;
            latLen++;
            lngTotal += path[i].lng;
            latTotal += path[i].lat;
        }
    }
    lng = lngTotal / lngLen;
    lat = latTotal / latLen;
    return [lng, lat];
}
function renderMarkerItem(options) {
    return {
        id: options.id,
        latitude: options.lat,
        longitude: options.lng,
        title: options.title,
        iconPath: options.iconPath,
        width: 30,
        height: 30,
        callout: {
            content: options.title,
            color: "#000",
            fontSize: 12,
            borderRadius: 5,
            bgColor: "#fff",
            padding: 5,
            display: "ALWAYS",
        },
    }
}
//经纬度转地址
function getRegeo(longitude, latitude) {
    return new Promise((resolve, reject) => {
        wx.request({
            url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=46WBZ-KBG3P-TRZDM-VTTYO-UF4LT-USBC4`,
            success(res) {
                resolve(res.data.result)
            },
            fail(err) {
                reject(err)
            }
        })
    })
}
export {
    filePathToBase64,
    previewImage,
    subscribeMessage,
    getPointsCenter,
    renderMarkerItem,
    getRegeo,
    urlToBase64
}